#include <stdlib.h>
#include <stdio.h>
#include "mp3.h"
void * MP3_Display(void * arg)
{
    int direction =(int)arg;
    char * mp3[5] = {"1.mp3", "2.mp3","3.mp3","4.mp3"};
    //播放第一个音乐 1.mp3 
    system("madplay -Q 1.mp3 &");
    int i = 0; //当前音乐文件的下标 
    int k=0;
    char cmd[52] = {0}; //保存执行音乐的指令字符串
    while(1)
    {
        //根据用户的输入，播放上一首/下一首
        if(direction == 0)
        {
            k=(k+1)%2;
            if(k)
                system("pkill -9 madplay"); //干掉当前播放的音乐
            if(!k)
            {
                sprintf(cmd, "madplay -Q %s &", mp3[i]);
                system(cmd);
            }
        }
        else if(direction == 1) //上一首
        {
            system("pkill -9 madplay");
            i--;
            if(i == -1)
            {
                i = 1;
            }
            sprintf(cmd, "madplay -Q %s &", mp3[i]);
            system(cmd);
        }
        else if(direction  == 2)
        {
            system("pkill -9 madplay");
            i++;
            if(i == 2)
            {
                i = 0;
            }
            sprintf(cmd, "madplay -Q %s &", mp3[i]);
            system(cmd);
        }
    }
}
